/* ===========================================================================
 *
 *       Filename:  zinnia_handwriting.h
 *
 *    Description:  zinnia_handwriting (qt)
 *
 * - Mode: 644
 * - NOTE. NOT use "dos"
 * - Updated: TODO
 *
 *        Version:  1.0.0
 *        Created:  2015-04-16 10:13:08
 *       Revision:  1.0.0
 *       Compiler:  moc/g++
 *
 *         Author:  Yui Wong, email: yuiwong@126.com
 *   Organization:  ""
 *        License:  LGPLv3
 *
 *  This file is part of portable-inputmethod.yw.
 *
 *  portable-inputmethod.yw
 *  is free software: you can redistribute it
 *  and/or modify it under the terms of the GNU General Public License as
 *  published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.
 *
 *  portable-inputmethod.yw
 *  is distributed in the hope that it will be
 *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with portable-inputmethod.yw.
 *  If not, see <http://www.gnu.org/licenses/>.
 *
 * ===========================================================================
 */


#if !defined(_ZINNIA_HANDWRITING_H_)
#define _ZINNIA_HANDWRITING_H_ (1)


#include <stdint.h>

#if !defined(ID_QT_VERSION)
#	error "ID_QT_VERSION NOT defined"
#endif

#include <QtCore/QTimer>
#include <QtGui/QMouseEvent>
#include <QtGui/QPaintEvent>

#if (ID_QT_VERSION < 0x050000)
#	include <QtGui/QWidget>
#	include <QtGui/QPushButton>
#	include <QtGui/QHBoxLayout>
#	include <QtGui/QVBoxLayout>
#else
#	include <QtWidgets/QWidget>
#	include <QtWidgets/QPushButton>
#	include <QtWidgets/QHBoxLayout>
#	include <QtWidgets/QVBoxLayout>
#endif

#include <zinnia.h> /* zinnia_character_t .. */
#include <LineStroke.h> /* class LineStroke */
#include <zinnia_handwriting_manager.h>


#define ZINNIA_HW_CB_NUM (10) /* max */


class zinnia_handwriting : public inputmethod {
	Q_OBJECT

friend class zinnia_handwriting_manager;

/*
 * INTERFACE(S)
 */
signals: void char_chose(const QWidget * focus,
	const char * utf8);/* 向其他窗口传递 utf8 cstr */


public: zinnia_handwriting(QWidget * parent = 0);
protected: virtual int reinitialize_core(QWidget * focus,
	const char * mf = 0);
public: ~zinnia_handwriting(void);


private: static char m[];/* model file */
private: static size_t writor_width_fixed;
private: static size_t writor_height_fixed;
private: static int writor_pen_w_fixed;


private: void do_deinit_core(void);
private: void CORE_READY(void);
private: bool core_initialized;
private: uint8_t access;


public: void mouseMoveEvent(QMouseEvent * evt);
public: void mousePressEvent(QMouseEvent * evt);
public: void mouseReleaseEvent(QMouseEvent * evt);
public: void paintEvent(QPaintEvent * evt);


public: void genbuttonstate(void);
public: void stok2qchar(void);
public: void append_stroke(LineStroke& stroke);
private: inputmethod_manager::click_state_t mouse_state;

public: LineStroke currentstroke;
public: QVector<LineStroke>  strokes;
public: zinnia_character_t * character;
public: zinnia_recognizer_t * recognizer;

protected slots: void recognize(void);
protected slots: void turnpageup(void);
protected slots: void turnpagedown(void);
protected slots: void choose_char(void);

private: QVBoxLayout * master_layout;
private: QHBoxLayout * writor_layout;
private: QVBoxLayout * option_layout;
private: QHBoxLayout * candidate_layout;
private: QPushButton * candidate_btns[ZINNIA_HW_CB_NUM];
private: QPushButton * up;
private: QPushButton * down;
private: bool is_self(const QWidget * w);
private slots: void restore_last_focus(QWidget * oldf, QWidget * newf);
private: QTimer recogtimer;
private: QWidget * focus;
private: QStringList dstr;
private: int index;
private: int allpage;
}; /* class zinnia_handwriting */


#endif /* !defined(_ZINNIA_HANDWRITING_H_) */


/*
 * end of file zinnia_handwriting.h
 */
